<template>
	<view v-if="show">
		<Header title="首页"></Header>
		
		<view class="faceInfo">
				<!-- <view>姓&#12288;名：{{info.ownerName||'无'}}</view> -->
				<view>学&#12288;校：{{info.organizationName||'无'}}</view>
		</view>
		
		<view class="bg">
			
		</view>
		
		<view v-for="(item,index) in list" class="box" :key="index">
			<view @click="toPath(it.path)" v-for="(it,idx) in item" :key="idx">
				<image :src="it.imgUrl" mode=""></image>
				<view>{{it.type}}</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show:false,
				info:'',
				list:[
					[
						{
							imgUrl:'../../static/class1.png',
							type:'班级',
							path:'/pages/class/class?id='
						},
						{
							imgUrl:'../../static/help.png',
							type:'帮助中心',
							path:''
						},
						{
							imgUrl:'../../static/exit.png',
							type:'退出',
							path:'退出'
						}
					]
				]
			}
		},
		onLoad(e) {
			if(e.isBind){
				this.getJG()
			}else{
				this.getOpenId()
			}
		},
		methods: {
			toPath(url){
				if(url=='退出'){
					this.$http('/authority/api/login/unBindWxId?openId=' + uni.getStorageSync('openId'), {}, res => {
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}, 'GET')
				}else{
					uni.navigateTo({
						url:url+this.info.id
					})
				}
			},
			getOpenId() {
				let that = this
				uni.login({
					success(res) {
						that.$http('/pay/api/wechart/getSessionNew',{
							appId:getApp().globalData.appId,
							code:res.code
						}, res1 => {
							uni.setStorageSync('openId',res1.data.openid)
							uni.setStorageSync('sk',res1.data.sk )
							that.getToken()
						}, 'GET')
					}
				})
			},
			getToken() {
				this.$http('/authority/api/login/verifyWxId?openid=' + uni.getStorageSync('openId'), {}, res => {
					uni.setStorageSync('token', res.data.token)
					this.getJG()
				}, 'GET', err => {
					uni.reLaunch({
						url: '/pages/login/login'
					})
				})
			},
			getJG(){
				this.$http('/member/api/organization/getOwnerList',{ "condition":{"isOrganization":true}},res=>{
					this.info = res.data.items[0]
					this.show = true
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.faceInfo{
		width: 100%;
		background-color: #2BAC6B;
		padding: 20upx 100upx;
		box-sizing: border-box;
		position: relative;
		>view{
			color: #FFFFFF;
			font-size: 30upx;
			height: 80upx;
			line-height: 80upx;
		}
		
	}
	
	.bg{
		width: 100%;
		background-image: url(../../static/img/bg.png);
		height: 100upx;
		background-size: 100% 100%;
	}
	.box{
		width: 90%;
		margin: 20upx auto 0;
		background-color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		padding: 45upx 0;
		border-radius: 8upx;
		>view{
			width: 33.3%;
			text-align: center;
			font-size: 28upx;
			>image{
				width: 60upx;
				height: 60upx;
			}
			>view{
				margin-top: 10upx;
				height: 40upx;
				line-height: 40upx;
			}
		}
	}
</style>